/**
 * @file 订单标签配置
 * @author liuying
 * @date 2021-07-30 15:24:11
 */

layui.define(['element', 'layer', 'form', 'colorpicker', 'zmnOmsSelect', '$http'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let $http = layui.$http;
    let layer = layui.layer;
    let zmnOmsSelect = layui.zmnOmsSelect;
    let colorpicker = layui.colorpicker;

    let CONF_BASE_URL = '/conf/ordertag';

    /**
     * 初始化页面事件
     */
    function initEvent() {
        // 监听保存按钮
        form.on('submit()', function (data) {
            var url = CONF_BASE_URL + '/save.action';
            $http.lockSave(url, data.field, data.elem).then(function (rsp) {
                layer.msg('操作成功', { icon: 1, time: 1000 }, function () {
                    parent.layer.closeAll();
                });
            }, (msg) => {
                layer.msg(msg);
            });
            return false
        });
    }

    function init() {
        initEvent();

        // 颜色选择
        colorpicker.render({
            elem: '#color-form',
            color: dataVo.color || '#e41414',
            done: function(color){
                $('#color').val(color);
            }
        });

        // 标记分类
        zmnOmsSelect.selectConfOrderTagCategory('categoryIds', {
            tips: "请选择分类",   //默认提示
            selectedValues: dataVo.categoryIds === null ? null : dataVo.categoryIds.split(","),
            page: {
                enable: true,
                remote:true,
                pageSize: 50
            },
            remote: {
                events: {
                    extendParams: function () {
                        return {
                            status: 2
                        }
                    }
                }
            }
        });
    }

    init();
    exports('oms_conf_ordertag_detail');
});
